<!DOCTYPE html>
<html lang="en">
<head>
    <title>投票结果</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">

    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <link href="/dist/css/oa-app.css" rel="stylesheet"/>
    <link href="votePublic.css" rel="stylesheet"/>
    <style>
        [v-cloak] {
            display: none;
        }
        input:focus {
            　　font-size: 16px !important;
        }
        * {
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            outline: none;
        }
        .oa-table td, .oa-table th {
            text-align: center;
            height: 40px;
            line-height: 40px;
            font-weight: normal;
            padding: 0 2px;
            border: none;
        }
        .fjBox{
            position: relative;
            overflow: hidden;
        }
        .selectBtn{

        }
        .oa-fj{
            background: #fff;
        }
        body {
            background: #fff;
        }

        .oa-fj .name{
            padding-right: 20px;
        }
        .lookBtn{
            position: absolute;
            right: 0;
            top: 0;
            padding-right: 10px;
            font-size: 14px;
            color: #2a8cec;
        }




        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            line-height: 20px;
            background-color: #d3e8fd;
            padding: 8px 6px;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 50px;
            top: -12px;
        }


        .oa-table tr th {
            text-align: center;
            font-size: 12px;
            margin-top: -1px;
            height: 30px;
            line-height: 30px;
        }

        .selectBtn{
            height: 20px;
            width: 20px;
            border: 2px solid #ddd;
            /* border-radius: 50%; */
            float: left;
            /* margin-top: 5px; */
            margin-left: 20px;
         }
        .selectBtn.active{
            border: 2px solid #ddd;
            background: #228bee;
            background-image: url("/dist/img/baiSeDuiGou.png");
            background-size: cover;
        }
    </style>
</head>
<body>
<section class="content" id="app" style="padding: 0px;padding-bottom: 50px;" v-cloak>
    <div class="div-td-content-more"><i></i></div>


    <table class="oa-table" v-for="(item,i) in list">
        <thead>
        <tr >
            <th>第{{number2big(item.rownum)}}名：{{item.name}}（{{item.num?item.num:'0'}}）
            </th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>
                <table class="oa-table">
                    <tbody>
                    <tr>
                        <td style="width: 60px">
                            <div :class="selectList.indexOf(item.themeId)>-1?'selectBtn active':'selectBtn'" @click="selectCx(item.themeId)"></div>
                        </td>
                        <td>
                            <div v-if="item.attr.attrName" class="fjBox" v-for="(item2,i2) in item.attr.attrUrlList">
                                <div class="oa-fj"   @click="lookFj(item.attr.attrUrlList[i2])">
                                    <b :class="fjStyle(item.attr.attrNameList[i2])"></b>
                                    <div class="name" v-if="item.attr.attrNameList[i2]" :title="item.attr.attrNameList[i2]">
                                        {{item.attr.attrNameList[i2]}}
                                    </div>
                                </div>
                                <div   class="lookBtn" @click="lookFj(item.attr.attrUrlList[i2])"  >查看</div>
                            </div>
                            <template v-else>
                                <div style="color: red;">未上传</div>
                            </template>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </td>
        </tr>

        </tbody>
    </table>

    <div class="oa-footer-btn" @click="saveSelect()" v-if="isSelect">提交</div> <!--正式使用不加  style="bottom:50px;"-->
    <div class="oa-footer-btn" v-else  @click="goBack">退出</div>

</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<script src="/dist/js/oaApp.js"></script>
<!--插件JS-->
<script type="text/javascript" src="/dist/plugins/vue/vue.js"></script>

<!--框架已定义 JS-->
<!--oa自定义  JS-->
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script>
    $(function () {
        $("body").on("click", ".center,.moreSpan", function (e) {
            if ($(".div-td-content-more").is(":hidden")) {
                var text = $(this).text();
                if (text != "") {
                    text = "<i></i>" + text;
                    $(".div-td-content-more").html(text).css({
                        "width": $(this).outerWidth() + "px",
                        "left": $(this).offset().left,
                        "top": ($(this).offset().top + $(this).outerHeight()) + "px"
                    }).show();
                    e.stopPropagation();
                }
            } else {
                $(".div-td-content-more").hide();
            }
        });
        $("body").on("click", ".div-td-content-more", function (e) {
            e.stopPropagation();
        });
        $("body").on("click", function () {
            $(".div-td-content-more").hide();
        });
    });
</script>
<script>
    $.ajaxSetup({
        global: true,
        type: "POST",
        cache: false,
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        beforeSend: function () {
        },
        complete: function () {

        },
        error: function (e) {
            alert('error' + e.responseText);
        }
    });
    $.extend($.wyui, {
        page: {
            urlParams: null,
            queryParams: {
                requestPage: 1,
                pageSize: 30
            },

            dataUrl: '',
            createQueryParams: function () {
            },
            getByPage: function (type) {
                $.ajax({
                    url: $.wyui.page.dataUrl,
                    data: JSON.stringify($.wyui.page.queryParams),
                    beforeSend: function () {

                    },
                    complete: function () {
                    },
                    success: function (r) {
                        $.wyui.page.queryParams.requestPage++;

                        if (r.data.sendData.pager && r.data.sendData.pager.pageCount == 0) {
                            r.data.sendData.pager.pageCount = 1;
                        }
                        if (type == "scroll") {
                            $.wyui.page.getByPage_scroll_callback(r.data.sendData.records);
                        } else {
                            if ($.wyui.page.getByPage_callback_new) {
                                $.wyui.page.getByPage_callback_new(r.data.sendData.records);
                            }
                        }

                    }
                });
            }
        },
        postMethod: function (url, data, callback, sync, id) {
            if (!id) {
                id = "#app"
            }
            $.ajax({
                url: server.ip + url,
                async: sync ? false : true,
                data: JSON.stringify(data),
                beforeSend: function () {

                },
                complete: function () {
                    setTimeout(function () {
                    }, 1000);

                },
                success: function (r) {
                    if (!r.e.code) {
                        callback(r.data.sendData);
                    } else {
                        alert(r.e.desc);
                    }
                },
                error: function (e) {
                    alert(url + e.responseText);
                }
            });
        },
    });
</script>
<script type="text/javascript">
    function NewDate(str){
        if(!str){
            return 0;
        }
        arr=str.split(" ");
        d=arr[0].split("-");
        t=arr[1].split(":");
        var date = new Date();
        date.setUTCFullYear(d[0], d[1] - 1, d[2]);
        date.setUTCHours(t[0]-8, t[1], t[2], 0);
        return date;
    }
    var query = null;
    var app = new Vue({
        el: '#app',
        data: {
            selectTree:0,
            selectBox:{
                companyList:[],
                departList:[],
                roleList:[],
                selectCompany:[],
                companyNames: [],
                departNames: [],
                roleNames: [],
                companyIds: [],
                userIds:[]
            },
            userInfo:{},
            userId: getUrlParamObj().userId,
            mainId:getUrlParamObj().mainId,
            title:getUrlParamObj().title,
            shareApp:getUrlParamObj().shareApp,
            date: "",
            list: [],
            mainInfo:{},
            auditInfo:"",
            isGo:true,
            selectList:[],
            info: {
                type: 3,
                createAuditors: [],
                auditors: [],
                auditFlag: "-5",
                auditInfo: "",
                title: "",
                content: "",
                endTime: '',
                uploadTime: '',
                voteUsers: "",
                createUserId: getUrlParamObj().userId,
                companyId: "",
                createUserName: "",
                voteThemeList: [
                    {
                        "title": "",
                        "value": [
                        ]
                    }
                ]
            },
            isSelect:true
        },
        methods: {
            goBack:function () {
                var param = {
                    backRefresh: true,       //是否返回刷新
                }
                JSBridge.call(ROUTER, 'navigateBack', param)
            },
            createNew:function (repaymentAttachName,repaymentAttachUrl) {
                var _this=this;
                $.wyui.postMethod("/exam/saveMain.json", {
                    createUserId:'',
                    createUserName:'',
                    description:"大区经理经验分享"+new Date().Format('M-d'),
                    repaymentAttachName:repaymentAttachName,
                    repaymentAttachUrl:repaymentAttachUrl
                }, function (res) {
                    _this.save();
                    console.log(res);
                });
            },
            saveSelect:function () {
                var _this=this;
                if(this.selectList.length>0){
                    var themeId=_this.selectList.join(",");
                    if (this.isGo) {
                        var param = {
                            title: "提交中...",
                        }
                        JSBridge.call(UI, 'showLoading', param)
                        _this.isGo = false;
                        //创建投票

                        $.wyui.postMethod("/vote/nomination.json", {
                            mainId: _this.mainId,
                            themeIds: themeId
                        }, function (info) {
                            //检测四省最新的一条是提交。
                            $.wyui.postMethod("/vote/selectIsCreate.json", {companyId: '2017121617464DFEB683A82815924552,2017121617484353B8D81EEAFB4598A6,2017121617484B3A8193DB9B6CB372AC,2017121617484BB9BEB4A635E7458410'}, function (res) {
                                console.log(res);
                                if (res.result.length == 4) {
                                    var ids = [];
                                    for (var i = 0; i < res.result.length; i++) {
                                        ids.push(res.result[i].ID)
                                    }
                                    $.wyui.postMethod("/vote/getThemesByMainIds.json", {mainId: ids.join(',')}, function (res) {
                                        var attrUrlList=[];
                                        var attrNameList=[];


                                        for (var i = 0; i < res.result.length; i++) {
                                            attrUrlList.push(res.result[i].attrUrl)
                                            attrNameList.push(res.result[i].attrName)
                                            _this.info.voteThemeList[0].value.push({
                                                "title": res.result[i].description,
                                                "disa": true,
                                                "attrUrl": res.result[i].attrUrl,
                                                "attrName": res.result[i].attrName
                                            })
                                        }
                                        var repaymentAttachName=attrNameList.join(',');
                                        repaymentAttachName.replaceAll(";",',');
                                        var repaymentAttachUrl=attrUrlList.join(',');
                                        repaymentAttachUrl.replaceAll(";",',');
                                        _this.createNew(repaymentAttachName,repaymentAttachUrl)
                                    });
                                } else {
                                    _this.isGo = true;
                                    JSBridge.call(UI, 'showToast', {title: "提交成功"})
                                    var param = {
                                        backRefresh: false,       //是否返回刷新
                                    }
                                    JSBridge.call(ROUTER, 'navigateBack', param)

                                    var url = '/page/voteApp/list.html?userId=' + _this.userId;
                                    var param = {
                                        screenType: '0',        //默认竖屏0, 横屏1
                                        title: '滚滚向前投票助手',         //顶部标题
                                        url: url, //路径
                                        showTitleBar: false,     //是否显示标题栏
                                        enableRefresh: false,   //是否启用下拉刷新
                                        backRefresh: true       //是否返回刷新
                                    }
                                    JSBridge.call(ROUTER, 'navigateTo', param)
                                }

                            });

                        });
                    }
                }else{
                    JSBridge.call(UI, 'showToast', {title: "请至少选择一位参选人员！"})
                }

            },
            save: function () {
                var _this = this;

                    this.info.title=new Date().Format(TimeFormat.pcListYR)+'优秀大区经理经验分享评比';
                    this.info.companyIds = '';
                    this.info.roleNames = '';
                    this.info.departNames = '';

                    this.info.createUserId = '';
                    this.info.createUserName = '';
                    this.info.companyId = '201712161613432EAF27DBCCB7D0E6CA';


                    $.wyui.postMethod("/vote/saveVote.json", _this.info, function (r) {
                        _this.isGo = true;
                        JSBridge.call(UI, 'hideLoading')
                        if (r.id) {
                            JSBridge.call(UI, 'showToast', {title: "优秀大区经理评比创建完成"})
                            var param = {
                                backRefresh: false,       //是否返回刷新
                            }
                            JSBridge.call(ROUTER, 'navigateBack', param)

                            var url='/page/voteApp/list.html?userId='+_this.userId;
                            var param = {
                                screenType: '0',        //默认竖屏0, 横屏1
                                title: '滚滚向前投票助手',         //顶部标题
                                url: url, //路径
                                showTitleBar: false,     //是否显示标题栏
                                enableRefresh: false,   //是否启用下拉刷新
                                backRefresh: true       //是否返回刷新
                            }
                            JSBridge.call(ROUTER, 'navigateTo', param)
                        } else {
                            JSBridge.call(UI, 'showToast', {title: "系统内容异常，请联系IT人员"})
                        }
                    });


            },


            lookFj:function (url) {
                console.log("1");
                var that = this
                var param = {
                    url: url,
                }
                JSBridge.call(FILE, 'showFile', param)
            },
            selectCx:function(id){
                if(this.isSelect){
                    if(this.selectList.indexOf(id)>-1){
                        if(this.selectList.length==1){
                            JSBridge.call(UI, 'showToast', {title: "请至少选择一位参选人员！"})
                        }else{
                            this.selectList.splice(this.selectList.indexOf(id),1);

                        }
                    }else{
                        this.selectList.push(id);
                    }
                }

            },
            fjStyle: function (fjName) {
                if (fjName) {
                    var type = fjName.substring(fjName.lastIndexOf('.') + 1);
                    return 'img fj-' + type
                }
                return 'img'
            },
            hideLoading: function () {
                JSBridge.call(UI, 'hideLoading')
            },
            goBack:function () {
                var param = {
                    backRefresh: true,       //是否返回刷新
                }
                JSBridge.call(ROUTER, 'navigateBack', param)
            },
            cancel:function (){
                this.userModel=false;
            },
            goreject:function(){
                var _this=this;
                var param = {
                    screenType: '0',        //默认竖屏0, 横屏1
                    title: '驳回',         //顶部标题
                    url: '/page/voteApp/reject.html?userId='+_this.userId+"&userName="+_this.userInfo.name+"&mainId="+_this.mainId, //路径
                    showTitleBar: false,     //是否显示标题栏
                    enableRefresh: false,   //是否启用下拉刷新
                    backRefresh: true       //是否返回刷新
                }
                JSBridge.call(ROUTER, 'navigateTo', param)
            },
            closeModel:function(){
                this.showModel=false;
            },
            compareDate:function(d1) {
                return ((new Date(d1)) > (new Date()));
            },
            initPage:function () {
                console.log("11")
                $('html,body').animate({scrollTop: '10000px'}, 100);
            },
            share:function () {
                var that = this
                var param = {
                    wxUserName: 'gh_e00723ba1af8',
                    wxPath: 'pages/result/result?id='+that.mainId+'&title='+that.title,
                    title: that.title,
                    content: that.title,
                    imgUrl: 'http://oa.yingfeng365.com/dist/img/tp2.jpg',
                    linkUrl: "http://oa.yingfeng365.com/page/voteApp/result.html?mainId="+that.mainId+"&title="+that.title+"&shareApp=true",
                    openMiniProgram: false //false需要应用和小程序需要绑定在同一微信开放平台账号下, 不同账号下传true
                }
                JSBridge.call(SHARE, 'showShareMiniProgram', param, function (res) {
                    that.showToast(res)
                })
            },
            number2big: function (number) {
                switch (Number(number)) {
                    case 1:
                        return '一';
                        break;
                    case 2:
                        return '二';
                        break;
                    case 3:
                        return '三';
                        break;
                    case 4:
                        return '四';
                        break;
                    case 5:
                        return '五';
                        break;
                    case 6:
                        return '六';
                        break;
                    case 7:
                        return '七';
                        break;
                    case 8:
                        return '八';
                        break;
                    case 9:
                        return '九';
                        break;
                    case 10:
                        return '十';
                        break;
                    case 11:
                        return '十一';
                        break;
                    case 12:
                        return '十二';
                        break;
                    case 13:
                        return '十三';
                        break;
                    case 14:
                        return '十四';
                        break;
                    case 15:
                        return '十五';
                        break;
                    case 16:
                        return '十六';
                        break;
                    case 17:
                        return '十七';
                        break;
                    case 18:
                        return '十八';
                        break;
                    case 19:
                        return '十九';
                        break;
                    case 20:
                        return '二十';
                        break;
                }
            },
            formatDate: function (now) {
                if(now) {
                    return new Date(now).Format(TimeFormat.middle)
                }
            },
            getMain:function () {
                JSBridge.call(UI, 'showLoading', {})
                var _this = this; //声明一个变量指向Vue实例this，保证作用域一致
                $.wyui.postMethod("/vote/getMainInfoById.json", {"mainId":_this.mainId}, function (res) {
                    var newList=[];
                    var nameList='';
                    var auditIds=[];
                    console.log(res);
                    if(res.audit&&res.audit.length>0){
                        for(var c=0;c<res.audit.length;c++){
                            auditIds.push(res.audit[c].auditorId);
                        }
                        res.auditAllIds=auditIds.join(",");
                    }else{
                        res.auditAllIds='';
                    }
                    if(res.assigner&&res.assigner.length>0){
                        if(res.auditFlag==0){
                            //审核过程中 展示所有重新指定结果
                            if(res.auditAllIds.indexOf(_this.userId)>-1||_this.userId==res.createUserId){
                                for(var i=0;i<res.assigner.length;i++){
                                    var data=res.assigner[i];
                                    var num=nameList.indexOf('%'+data.assigner+'%');

                                    if(num==-1){
                                        nameList+='%'+res.assigner[i].assigner+'%';
                                        var obj={};
                                        obj.name=data.assigner;
                                        obj.list=[];
                                        for(var a=0;a<res.assigner.length;a++){
                                            var item=res.assigner[a];
                                            if(data.assigner==item.assigner){
                                                obj.list.push(item)
                                            }
                                        }
                                        newList.push(obj);
                                    }

                                }

                            }
                        }else if(res.auditFlag==1){
                            //通过 只展示最后一位审核人的
                            for(var i=0;i<res.assigner.length;i++){
                                var data=res.assigner[i];

                                if(data.createUserName==res.currentAuditorName){
                                    var obj={};
                                    obj.name=data.assigner;
                                    obj.list=[];
                                    for(var a=0;a<res.assigner.length;a++){
                                        var item=res.assigner[a];
                                        if(data.assigner==item.assigner){
                                            obj.list.push(item)
                                        }
                                    }
                                    newList.push(obj);
                                }

                            }
                        }

                        res.assigner=newList;
                    }


                    _this.mainInfo=res;
                    _this.hideLoading()
                });
            }
        },
        mounted: function () {
            var _this = this; //声明一个变量指向Vue实例this，保证作用域一致
            JSBridge.call(UI, 'showLoading', {})
            _this.date = new Date().Format("hh:mm"); //修改数据date
            this.timer = setInterval(function () {
                _this.date = new Date().Format("hh:mm"); //修改数据date
            }, 1000)
            this.getMain();

            if(_this.userId) {
                $.wyui.postMethod("/vote/getUserInfoByUserId.json", {id: _this.userId}, function (info) {
                    _this.userInfo = info.userInfo;
                });
            }

            $.wyui.postMethod("/vote/getResultListAndAttr.json", {"mainId":_this.mainId}, function (res) {
                console.log(res);
                for(var i=0;i<res.result.length;i++){
                    if(res.result[i].attr.attrUrl){
                        res.result[i].attr.attrUrlList=res.result[i].attr.attrUrl.split(';');
                        res.result[i].attr.attrNameList=res.result[i].attr.attrName.split(';');
                    }else{
                        res.result[i].attr.attrUrlList=[];
                        res.result[i].attr.attrNameList=[];
                    }
                    if(res.result[i].attr.nomination==1){
                        _this.selectList.push(res.result[i].themeId)
                        _this.isSelect=false;
                    }
                }
                _this.list=res.result;

            });

        }
    });

</script>
</body>